import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */


export const constantRoutes = [
   //主页菜单
  {
    path: '/',
    component: Layout,
    redirect: '/myHome',
    meta: { title: '个人主页', icon: 'people' },
    children: [
      {
        path: 'myHome',
        name: 'MyHome',
        component: () => import('@/views/myhome/index'),
        meta: { title: '我的主页', icon: 'education' },
      },
      {
        path: 'registration',
        name: 'Registration',
        component: () => import('@/views/myhome/registration'),
        meta: { title: '选课中心', icon: 'education' },
      },
      {
        path: 'allTrain',
        name: 'AllTrain',
        component: () => import('@/views/myhome/allTrain'),
        meta: { title: '培训项目', icon: 'education' },
      },
      {
        path: 'myTrain',
        name: 'MyTrain',
        component: () => import('@/views/item/myitem'),
        meta: { title: '我的培训', icon: 'education' },
        
      },
      {
        path: 'myRequired',
        name: 'MyRequired',
        component: () => import('@/views/course/myrequired'),
        meta: { title: '我的必修', icon: 'education' }
      },
      {
        path: 'myElective',
        name: 'MyElective',
        component: () => import('@/views/course/myelective'),
        meta: { title: '我的选修', icon: 'education' }
      }
    ]
  },
  {

    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/myinfo',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        hidden: true,
        component: () => import('@/views/myhome/myinfo/myinfo'),
        meta: { title: '个人信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/updatepass',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('../views/myhome/myinfo/updatepass'),
        meta: { title: '账号安全', icon: 'form' }
      }
    ]
  },{
    path: '/train',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'trainDetails',
        component: () => import('../views/train/trainDetails'),
        meta: { title: '培训详情', icon: 'form' }
      }
    ]
  },
  {
    path: '/train2',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'trainDetails2',
        component: () => import('../views/train/trainDetails2'),
        meta: { title: '培训详情二', icon: 'form' }
      }
    ]
  },{
    path: '/studentDetails',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'studentDetails',
        name: 'studentDetails',
        component: () => import('../views/manage/studentmanage/studentDetails'),
        meta: { title: '学员详情页1', icon: 'form' }
      }
    ]
  },
  {
    path: '/coursePage',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'coursePage',
        name: 'coursePage',
        component: () => import('../views/course/coursePage'),
        meta: { title: '课程视频', icon: 'form' }
      },
      {
        path: 'courseDetails',
        name: 'courseDetails',
        hidden:true,
        component: () => import('../views/course/details/courseDetails'),
        meta: { title: '课程详情页', icon: 'form' }
      },
    ]
  },
  
]

//异步挂载的路由
//动态需要根据权限加载的路由表 
export const asyncRoutes = [
  //需求菜单
  {
    path: '/demandHome',
    component: Layout,
    redirect: '/demandHome',
    meta: { title: '培训需求', icon: 'drag', roles: ['admin', 'superAdmin'] },
    children: [
      {
        path: 'demandHome',
        name: 'DemandHome',
        component: () => import('@/views/demandhome/index'),
        meta: { title: '需求主页', icon: 'documentation' },
      },
      {
        path: 'demandRelease',
        name: 'DemandRelease',
        component: () => import('@/views/demandhome/demandgo/index'),
        meta: { title: '需求发布', icon: 'documentation' }
      },
      { 
        path: 'demandTemplate',
        name: 'DemandTemplate',
        hidden: true,
        component: () => import('@/views/research/researchTemplate'),
        meta: { title: '调研模版', icon: 'documentation' },
      },
      { 
        path: 'demandTemplates',
        name: 'DemandTemplate',
        hidden: true,
        component: () => import('@/views/research/researchTemplates'),
        meta: { title: '调研模版2', icon: 'documentation' },
      },
      { 
        path: 'researchResult',
        name: 'ResearchResult',
        hidden: true,
        component: () => import('@/views/research/researchResult'),
        meta: { title: '详情页面', icon: 'documentation' },
      },
      {
        path: 'myCollect',
        name: 'MyCollect',
        hidden: true,
        component: () => import('@/views/demandhome/demandcollect/index'),
        meta: { title: '我的收集', icon: 'documentation' }
      }
    ]
  },

  //计划菜单
  {
    path: '/planHome',
    component: Layout,
    redirect: '/planHome',
    meta: { title: '培训计划', icon: 'fullscreen', roles: ['admin','deptLeader', 'superAdmin'] },
    children: [
      {
        path: 'planHome',
        name: 'PlanHome',
        component: () => import('@/views/plan/index'),
        meta: { title: '培训计划', icon: 'edit', roles: ['admin', 'superAdmin','deptLeader'] },
        
      },
      {
        path:'approve',
        name:'Approve',
        component: () => import('@/views/plan/planapprove/index'),
        meta: { title: '我的审批', icon: 'edit', roles:['deptLeader']},
        children:[
          {
            path: 'approveNow',
            name: 'ApproveNow',
            component: () => import('@/views/plan/planapprove/waitapprove'),
            meta: { title: '待审批', icon: 'edit' },
          },
          {
            path: 'approved',
            name: 'Approved',
            component: () => import('@/views/plan/planapprove/approved'),
            meta: { title: '已审批', icon: 'edit' },
          },
        ]
      },
      {
        path: 'planRelease',
        name: 'PlanRelease',
        component: () => import('@/views/plan/planpublish/index'),
        meta: { title: '计划发布', icon: 'edit', roles: ['admin', 'superAdmin'] }
      },
      
    ]
  },
  //管理菜单
  {
    path: '/studentManage',
    component: Layout,
    redirect: '/studentManage',
    meta: { title: '培训管理', icon: 'exit-fullscreen', roles: ['admin', 'superAdmin'] },
    children: [
      {
        path: 'studentManage',
        name: 'StudentManage',
        component: () => import('@/views/manage/studentmanage/student'),
        meta: { title: '学员管理', icon: 'list' },
        children:[ 
          {
            path: '/studentDetails',
            component: Layout,
            hidden: true,
            children: [
              {
                path: 'studentDetails',
                name: 'studentDetails',
                component: () => import('../views/manage/studentmanage/studentDetails'),
                meta: { title: '学员详情页1', icon: 'form' }
              }
            ]
          },        
        ]
      },
      {
        path: 'courseManage',
        name: 'CourseManage',
        component: () => import('@/views/course/index'),
        meta: { title: '课程管理', icon: 'list' },
        
      },
      {
        path: 'createCourse',
        name: 'createCourse',
        component: () => import('@/views/course/createCourse'),
        meta: { title: '新增课程', icon: 'list' }
      }
    ]
    
  },
  //实施菜单
  {
    path: '/item',
    component: Layout,
    redirect: '/home',
    meta: { title: '培训实施', icon: 'tab', roles: ['admin', 'superAdmin'] },
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/item/index'),
        meta: { title: '培训项目主页', icon: 'example' },
      },
      {
        path: '/create',
        name: 'Create',
        component: () => import('@/views/item/createItem'),
        meta: { title: '新建培训项目', icon: 'example' }
      },
      {
        path: '/manage',
        name: 'Manage',
        hidden: true,
        component: () => import('@/views/item/detail/index'),
        meta: { title: '培训项目管理', icon: 'example' }
      }
    ]
  },
  //基础设置菜单
  {
    path: '/setting',
    component: Layout,
    redirect: '/roleManage',
    meta: { title: '基础设置', icon: 'tab', roles: ['superAdmin'] },
    children: [
      {
        path: '/roleManage',
        name: 'RoleManage',
        component: () => import('@/views/role/index'),
        meta: { title: '角色管理', icon: 'tree', roles: ['superAdmin'] }
      }
    ]
  },
  
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router